package com.yupi.springbootinit.spark;

import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.yupi.springbootinit.utils.AuthUtils;
import okhttp3.*;

import javax.annotation.Resource;

public class SparkManager {

    @Resource
    SparkConfig sparkConfig;
    private String host;
    private String path;
    private String apiSecret;
    private String apiKey;

    public String doChat(long userId,String question) throws Exception {
        // 构建鉴权url
        String authUrl = AuthUtils.genAuthUrl(apiKey, apiSecret, host, path);
//        OkHttpClient client = new OkHttpClient.Builder().build();
        // 构建websocket请求
        Request request = new Request.Builder().url(authUrl).build();
        SparkChat sparkChat = new SparkChat(sparkConfig, userId,question);
        // 发起websocket请求
//        WebSocket webSocket = client.newWebSocket(request,sparkChat );
//        return sparkChat.getTotalAnswer().toString();
        return "";
    }
}
